package teacher.service.laohe;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import teacher.bean.Award;
import teacher.bean.Paper;
import teacher.bean.Patent;
import teacher.bean.Project;
import teacher.bean.Teacher;
import teacher.bean.Treatise;
import database.dao.MysqlCrud;

public class Static {
	
	public int getAwardCountByUser(Award award,String date2,Teacher teacher){
//		//String sql= "SELECT * FROM award WHERE state=? and awaId LIMIT " +
//				""+(pageNow-1)+" ,"+pageSize+"";
		int count=0;
		List<Award> awards=new ArrayList<Award>();
		String sql="select count(*) from award as A , teacher as T where A.teaId=T.teaId and T.user=? ";
		List<String> sql1=new ArrayList<String>();
		List<String> paras=new ArrayList<String>();
		
		paras.add(teacher.getUser());
		System.out.println("参数的尺寸为:"+paras.size());
		if(award!=null)
		{
			if(award.getName()!=null)
			{
				sql1.add(" A.name like ? ");
				paras.add("%"+String.valueOf(award.getName())+"%");
			}
			if(award.getProjectName()!=null)
			{
				sql1.add(" A.projectName like ? ");
				paras.add("%"+String.valueOf(award.getProjectName())+"%");
			}
			if(award.getLevel()!=null)
			{
				sql1.add(" A.level=? ");
				paras.add(String.valueOf(award.getLevel()));
			}
			if(award.getPeople()!=null)
			{
				sql1.add(" A.people like ? ");
				paras.add("%"+String.valueOf(award.getPeople())+"%");
			}
			if(award.getDate()!=null)
			{
				sql1.add(" A.date>=? and A.date<=? ");
				paras.add(String.valueOf(award.getDate()));
				paras.add(date2);
				
			}
			if(award.getKind()!=null)
			{
				sql1.add(" A.kind=? ");
				paras.add(String.valueOf(award.getKind()));
			}
			if(award.getEmpowerUnit()!=null)
			{
				sql1.add(" A.empowerUnit=? ");
				paras.add(String.valueOf(award.getEmpowerUnit()));
			}
		}
		for(int i=0;i<sql1.size();i++)
		{
			sql+="and"+sql1.get(i);
		}
		String[] parameter=new String[paras.size()];
		for(int i=0;i<paras.size();i++)
		{
			parameter[i]=paras.get(i);
		}
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> lists=mysqlcurd.SelectData(sql, parameter);
		Map map=lists.get(0);
		count=Integer.parseInt(map.get(0).toString());
		return count;
	}
	public int getPaperCountByUser(Paper paper,String date2,Teacher teacher) {
//		String sql= "select * from paper WHERE date>='"+date1+"' and date<='"+date2+"' and papId LIMIT " +
//				""+(pageNow-1)+" ,"+pageSize+"";
		String sql="select count(*) from paper as P,teacher as T where P.teaId=T.teaId and T.user=? ";
		int count=0;
		List<Paper> papers=new ArrayList<Paper>();
		List<String> sql1=new ArrayList<String>();
		List<String> paras=new ArrayList<String>();
		
		paras.add(teacher.getUser());
		if(paper!=null)
		{
			if(paper.getDate()!=null)
			{
				sql1.add(" P.date>=? and P.date<=? ");
				paras.add(String.valueOf(paper.getDate()));
				paras.add(date2);
			}
			if(paper.getName()!=null)
			{
				sql1.add(" P.name like ? ");
				paras.add("%"+String.valueOf(paper.getName())+"%");
			}
			if(paper.getEsi()!=null)
			{
				sql1.add(" P.esi=? ");
				paras.add(String.valueOf(paper.getEsi()));
			}
			if(paper.getFauthor()!=null)
			{
				sql1.add(" P.fauthor=? ");
				paras.add(String.valueOf(paper.getFauthor()));
			}
			if(paper.getInclude()!=null)
			{
				sql1.add(" P.include=? ");
				paras.add(String.valueOf(paper.getInclude()));
			}
			if(paper.getJclass()!=null)
			{
				sql1.add(" P.jclass=? ");
				paras.add(String.valueOf(paper.getJclass()));
			}
			if(paper.getPapId()!=null)
			{
				sql1.add(" P.papId=? ");
				paras.add(String.valueOf(paper.getPapId()));
			}
			if(paper.getPbulication()!=null)
			{
				sql1.add(" P.pbulication like ? ");
				paras.add("%"+String.valueOf(paper.getPbulication())+"%");
			}
			if(paper.getPubPage()!=null)
			{
				sql1.add(" P.pubPage=? ");
				paras.add(String.valueOf(paper.getPubPage()));
			}
			if(paper.getType()!=null)
			{
				sql1.add(" P.type=? ");
				paras.add(String.valueOf(paper.getType()));
			}
			if(paper.getPubNumber()!=null)
			{
				sql1.add(" P.pubNumber=? ");
				paras.add(String.valueOf(paper.getPubNumber()));
			}
			if(paper.getTopStu()!=null)
			{
				sql1.add(" P.topStu=? ");
				paras.add(String.valueOf(paper.getTopStu()));
			}
			if(paper.getTauthor()!=null)
			{
				sql1.add(" P.tauthor like ? ");
				paras.add("%"+String.valueOf(paper.getTauthor())+"%");
			}
			if(paper.getOauthor()!=null)
			{
				sql1.add(" P.oauthor like ? ");
				paras.add("%"+String.valueOf(paper.getOauthor())+"%");
			}
			if(paper.getMeetClass()!=null)
			{
				sql1.add(" P.meetClass=? ");
				paras.add(String.valueOf(paper.getMeetClass()));
			}
		}
		
		for(int i=0;i<sql1.size();i++)
		{
			sql+="and"+sql1.get(i);
		}
		String[] parameter=new String[paras.size()];
		for(int i=0;i<paras.size();i++)
		{
			parameter[i]=paras.get(i);
		}
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> lists=mysqlcurd.SelectData(sql, parameter);
		Map map=lists.get(0);
		count=Integer.parseInt(map.get(0).toString());
		return count;
	}
	public int getPatentCountByUser(Patent patent,String empowerDate2,String applyDate2,Teacher teacher) {
//		String sql= "select * from patent WHERE empowerDate>='"+date1+"' and empowerDate<='"+date2+"' and patId LIMIT " +
//				""+(pageNow-1)+" ,"+pageSize+"";
		String sql="select count(*) from patent as P,teacher as T where P.teaId=T.teaId and T.user=? ";
		int count=0;
		List<Patent> patents=new ArrayList<Patent>();
		List<String> sql1=new ArrayList<String>();
		List<String> paras=new ArrayList<String>();
		
		paras.add(teacher.getUser());
		if(patent!=null)
		{
			if(patent.getName()!=null)
			{
				sql1.add(" P.name like ? ");
				paras.add("%"+String.valueOf(patent.getName())+"%");
			}
			if(patent.getFiestInventor()!=null)
			{
				sql1.add(" P.fiestInventor like ? ");
				paras.add("%"+String.valueOf(patent.getFiestInventor())+"%");
			}
			if(patent.getEmpowerDate()!=null)
			{
				sql1.add(" P.empowerDate>=? and P.empowerDate<=? ");
				paras.add(String.valueOf(patent.getEmpowerDate()));
				paras.add(empowerDate2);
			}
			if(patent.getEmpowerUnit()!=null)
			{
				sql1.add(" P.empowerUnit=? ");
				paras.add(String.valueOf(patent.getEmpowerUnit()));
			}
			if(patent.getApplyNumber()!=null)
			{
				sql1.add(" P.applyNumber=? ");
				paras.add(String.valueOf(patent.getNumber()));
			}
			if(patent.getExpClass()!=null)
			{
				sql1.add(" P.expClass=? ");
				paras.add(String.valueOf(patent.getExpClass()));
			}
			if(patent.getEmpowerNum()!=null)
			{
				sql1.add(" P.empowerNum=? ");
				paras.add(String.valueOf(patent.getEmpowerNum()));
			}
			if(patent.getApplyDate()!=null)
			{
				sql1.add(" P.applyDate>=? and P.applyDate<=? ");
				paras.add(String.valueOf(patent.getApplyDate()));
				paras.add(applyDate2);
			}
		}
		for(int i=0;i<sql1.size();i++)
		{
			sql+="and"+sql1.get(i);
		}
		String[] parameter=new String[paras.size()];
		for(int i=0;i<paras.size();i++)
		{
			parameter[i]=paras.get(i);
		}
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectData(sql, parameter);
		Map map =list.get(0);
		count=Integer.parseInt(map.get(0).toString());
		return count;
	}
	public int getProjectCountByUser(Project project,Teacher teacher) {
//		String sql= "select * from project WHERE finishDate>='"+date1+"' and finishDate<='"+date2+"' and proId LIMIT " +
//				""+(pageNow-1)+" ,"+pageSize+"";
		String sql="select count(*) from project as P,teacher as T where P.teaId=T.teaId and T.user=? ";
		int count=0;
		List<String> sql1=new ArrayList<String>();
		List<String> paras=new ArrayList<String>();
		List<Project> projects=new ArrayList<Project>();
		
		paras.add(teacher.getUser());
		if(project!=null)
		{
			if(project.getName()!=null)
			{
				sql1.add(" P.name like ? ");
				paras.add("%"+String.valueOf(project.getName())+"%");
			}
			if(project.getLevel()!=null)
			{
				sql1.add(" P.level=? ");
				paras.add(String.valueOf(project.getLevel()));
			}
			if(project.getFinishDate()!=null)
			{
				sql1.add(" P.finishDate>=? and P.finishDate<=? ");
				paras.add(String.valueOf(project.getBeginDate()));
				paras.add(String.valueOf(project.getFinishDate()));
			}
			if(project.getSource()!=null)
			{
				sql1.add(" P.source=? ");
				paras.add(String.valueOf(project.getSource()));
			}
			if(project.getFunds()!=null)
			{
				sql1.add(" P.funds=? ");
				paras.add(String.valueOf(project.getFunds()));
			}
			if(project.getArriveFunds()!=null)
			{
				sql1.add(" P.arriveFunds=? ");
				paras.add(String.valueOf(project.getArriveFunds()));
			}
			if(project.getLeader()!=null)
			{
				sql1.add(" P.leader like ? ");
				paras.add("%"+String.valueOf(project.getLeader())+"%");
			}
			if(project.getOthers()!=null)
			{
				sql1.add(" P.others like ? ");
				paras.add("%"+String.valueOf(project.getOthers())+"%");
			}
			if(project.getClass_()!=null)
			{
				sql1.add(" P.class=? ");
				paras.add(String.valueOf(project.getClass_()));
			}
			if(project.getNumber()!=null)
			{
				sql1.add(" P.number=? ");
				paras.add(String.valueOf(project.getNumber()));
			}
			if(project.getKind()!=null)
			{
				sql1.add(" P.kind=? ");
				paras.add(String.valueOf(project.getKind()));
			}
			if(project. getProgress()!=null)
			{
				sql1.add(" P.progress=? ");
				paras.add(String.valueOf(project. getProgress()));
			}
		}
		for(int i=0;i<sql1.size();i++)
		{
			sql+="and"+sql1.get(i);
		}
		String[] parameter=new String[paras.size()];
		for(int i=0;i<paras.size();i++)
		{
			parameter[i]=paras.get(i);
		}
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectData(sql, parameter);
		Map map =list.get(0);
		count=Integer.parseInt(map.get(0).toString());
		return count;
	}
	public int getTreatiseCountByUser(Treatise treatise,String date2,Teacher teacher) {
//		String sql= "select * from treatise WHERE date>='"+date1+"' and date<='"+date2+"' and treId LIMIT " +
//				""+(pageNow-1)+" ,"+pageSize+"";
		int count=0;
		String sql="select count(*) from treatise as Tr,teacher as T where Tr.teaId=T.teaId and T.user=? ";
		List<Treatise> treatises=new ArrayList<Treatise>();
		List<String> sql1=new ArrayList<String>();
		List<String> paras=new ArrayList<String>();
		
		paras.add(teacher.getUser());
		if(treatise!=null)
		{
			if(treatise.getName()!=null)
			{
				sql1.add(" Tr.name like ? ");
				paras.add("%"+String.valueOf(treatise.getName())+"%");
			}
			
			if(treatise.getDate()!=null)
			{
				sql1.add(" Tr.date>=? and Tr.date<=? ");
				paras.add(String.valueOf(treatise.getDate()));
				paras.add(date2);
			}
			if(treatise.getAuthor()!=null)
			{
				sql1.add(" Tr.author like ? ");
				paras.add("%"+String.valueOf(treatise.getAuthor())+"%");
			}
			if(treatise.getState()!=null)
			{
				sql1.add(" Tr.state=? ");
				paras.add(String.valueOf(treatise.getState()));
			}
			if(treatise.getClass_()!=null)
			{
				sql1.add(" Tr.class=? ");
				paras.add(String.valueOf(treatise.getClass_()));
			}
			if(treatise.getPress()!=null)
			{
				sql1.add(" Tr.press=? ");
				paras.add(String.valueOf(treatise.getPress()));
			}
			if(treatise.getBookNum()!=null)
			{
				sql1.add(" Tr.bookNum=? ");
				paras.add(String.valueOf(treatise.getBookNum()));
			}
		}
		for(int i=0;i<sql1.size();i++)
		{
			sql+="and"+sql1.get(i);
		}
		String[] parameter=new String[paras.size()];
		for(int i=0;i<paras.size();i++)
		{
			parameter[i]=paras.get(i);
		}
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectData(sql, parameter);
		Map map =list.get(0);
		count=Integer.parseInt(map.get(0).toString());
		return count;
	}

}
